home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 6_1.lha / 6_1 / 6_1c.c < prev    next >
C/C++ Source or Header  |  1993-08-08  |  440b  |  19 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / exercise 6.1
  6. / string "add to end" operator
  7. tring& string::operator+=(string& st2)
  8.  
  9.    char *s1 = p->s;
  10.    char *s2 = st2.p->s;
  11.    int s1len = strlen(s1);
  12.    char *ns = new char[s1len + strlen(s2) + 1];
  13.    strcpy(ns, s1);
  14.    strcpy(ns + s1len, s2);
  15.    delete s1;
  16.    p->s = ns;
  17.    return *this;
  18.  
  19.